package edu.whut.Test;

import edu.whut.domain.Student;

import java.util.ArrayList;

/*
定义一个方法，接受集合对象，
将低于18的学生找到，并存入新的集合，返回新集合
 */
public class test04 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student stu1 = new Student("啊啊",14);
        Student stu2 = new Student("周琦",17);
        Student stu3 = new Student("艾伦",19);
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);

        ArrayList<Student> newlist = getNewStudents(list);
        for (int i = 0; i < newlist.size(); i++) {
            System.out.println(newlist.get(i).getName()+newlist.get(i).getAge());
        }

    }

    private static ArrayList<Student> getNewStudents(ArrayList<Student> list) {
        ArrayList<Student> newlist = new ArrayList<>();
        Student student = new Student();
        for (int i = 0; i < list.size(); i++) {
            student = list.get(i);
            if (student.getAge()<18){
                newlist.add(student);
            }
        }
        return newlist;
    }
}
